#include<bits/stdc++.h>
using namespace std;
const int mod = 6661;
pair<long long,int> a[1000003];
int idx;
set<pair<int,int> > st;
int C[mod + 4][mod + 4],s[mod + 4][mod + 4];
int sgl(long long x,int r)
{
	if(!r) return 1;
	if(x < r) return 0;
	if(x < mod) return C[x][r];
	return sgl(x / mod,r / mod) * C[x % mod][r % mod] % mod;
}
int qry(long long x,int r)
{
	if(x < mod)
		return s[x][r];
	if(!r)
		return 1;
	if(r < mod)
		return s[x % mod][r];
	return (s[x % mod][mod - 1] * qry(x / mod,(r - mod) / mod) + sgl(x / mod,r / mod) * s[x % mod][r % mod]) % mod;
}
bool vis[1000003];
int n,m;
long long k;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("izumi.in","r",stdin);
	freopen("izumi.out","w",stdout);
	C[0][0] = 1;
	for(int i = 1;i < mod;i++)
	{
		C[i][0] = 1;
		for(int j = 1;j <= i;j++)
			C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
	}
	for(int i = 0;i < mod;i++)
	{
		for(int j = 0;j < mod;j++)
			s[i][j] = C[i][j];
		for(int j = 1;j < mod;j++)
			s[i][j] = (s[i][j] + s[i][j - 1]) % mod;
	}
	cin >> n >> m >> k;
	a[idx = 1] = {k,0};
	vis[0] = vis[n] = 1;
	st.insert({n,1});
	while(m--)
	{
		int opt,l,r;
		cin >> opt >> l >> r;
		if(opt == 1)
		{
			cin >> k;
			if(!vis[l - 1])
			{
				vis[l - 1] = 1;
				auto x = st.lower_bound({l,0});
				st.insert({l - 1,(*x).second});
			}
			auto x = st.lower_bound({l,0});
			while(x != st.end() && (*x).first <= r)
			{
				vis[(*x).first] = 0;
				st.erase(x);
				x = st.lower_bound({l,0});
			}
			vis[r] = 1;
			a[++idx] = {k,l - 1};
			st.insert({r,idx});
		}else{
			long long ans = 0;
			auto x = st.lower_bound({l,0});
			while((*x).first < r)
			{
				int p = (*x).second;
				ans += qry(a[p].first,(*x).first - a[p].second) + mod - qry(a[p].first,l - a[p].second - 1);
				l = (*x).first + 1;
				x++;
			}
			int p = (*x).second;
			ans += qry(a[p].first,r - a[p].second) + mod - qry(a[p].first,l - a[p].second - 1);
			cout << ans % mod << "\n";
		}
	}
	return 0;
}